package com.cyf.db.mapper;

import com.cyf.db.bean.FeeDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface FeeDetailMapper {

    @Insert("insert into local_feedetail(feeType, createdUserId, createdUserName, cloudPersonId, personID, personName, recharge, createdTime, parkingId, paidOnline) "
            + "values(#{feeDetail.feeType}, #{feeDetail.createdUserId}, #{feeDetail.createdUserName}, #{feeDetail.cloudPersonId}, #{feeDetail.personId}, #{feeDetail.personName},"
            + "#{feeDetail.recharge}, #{feeDetail.createdTime}, #{feeDetail.parkingId}, #{feeDetail.paidOnline})")
    @SelectKey(statement = "select LAST_INSERT_ID()", keyProperty = "feeDetail.id", before = false, resultType = int.class)
    void insertCarRecharge(@Param("feeDetail") FeeDetail feeDetail);

    // TODO: 2017/3/27 北清创意园有旧数据，影响，此处暂时使用List,之后改为FeeDetail
    @Select("select * from local_feedetail where inoutParkingId = #{inoutParkingId} and parkingId = #{parkingId}")
    List<FeeDetail> getByInoutParkingId(@Param("inoutParkingId") Integer inoutParkingId, @Param("parkingId") Integer parkingId);

    // TODO: 2017/3/27 北清创意园有旧数据，影响，此处暂时使用List,之后改为FeeDetail
    @Select("select * from local_feedetail where cloudInoutParkingId = #{cloudInoutParkingId} and parkingId = #{parkingId}")
    List<FeeDetail> getByCloudInoutParkingId(@Param("cloudInoutParkingId") Integer cloudInoutParkingId, @Param("parkingId") Integer parkingId);

    @Select("SELECT SUM(actualfee) + SUM(wechatFee) " +
            "from local_feedetail " +
            "where parkingId = #{parkingId}  and inoutParkingId = #{inoutParkingId} " +
            "and license in (#{plate1},#{plate2},#{plate3})"
    )
    Integer getSumActualFeeAndWechatFee(@Param("plate1") String plate1,
                                        @Param("plate2") String plate2,
                                        @Param("plate3") String plate3,
                                        @Param("parkingId") Integer parkingId,
                                        @Param("inoutParkingId") Integer localInoutparkingId);

    @Select("SELECT sum((actualfee + wechatFee)) AS actualfee  FROM local_feedetail WHERE inoutParkingId = #{localInoutParkingId} AND parkingId = #{parkingId} ")
    Integer getPaymentAmount(@Param("localInoutParkingId") Integer localInoutParkingId,@Param("parkingId") Integer parkingId);
}
